# -*- coding: utf-8 -*-
import xadmin

from .models import Course, CourseResource, Lesson, Video


class LessonInline(object):
    model = Lesson
    extra = 0


class CourseResourceInline(object):
    model = CourseResource
    extra = 0


class CourseAdmin(object):
    list_display = ['name', 'desc', 'course_org', 'degree', 'learn_time', 'students', 'fav_nums', 'category', 'click_nums', 'add_time']
    search_fields = ['name', 'desc', 'course_org', 'degree', 'learn_time', 'students', 'fav_nums', 'category', 'click_nums']
    list_filter = ['name', 'desc', 'course_org', 'degree', 'learn_time', 'students', 'fav_nums', 'category', 'click_nums', 'add_time']
    # 后台默认排序
    ordering = ['-fav_nums']
    # 设置页面只读的字段
    readonly_fields = ['fav_nums',]
    # 设置页面不显示的字段
    exclude = ['click_nums',]

    inlines = [LessonInline, CourseResourceInline]


class LessonAdmin(object):
    list_display = ['course', 'name', 'add_time']
    search_fields = ['course', 'name']
    list_filter = ['course__name', 'name', 'add_time']


class VideoAdmin(object):
    list_display = ['lesson', 'name', 'add_time']
    search_fields = ['course', 'name']
    list_filter = ['lesson', 'name', 'add_time']


class CourseResourceAdmin(object):
    list_display = ['course', 'name', 'download', 'add_time']
    search_fields = ['course', 'name', 'download']
    list_filter = ['course', 'name', 'download', 'add_time']

xadmin.site.register(Course, CourseAdmin)
xadmin.site.register(Lesson, LessonAdmin)
xadmin.site.register(Video, VideoAdmin)
xadmin.site.register(CourseResource, CourseResourceAdmin)

